home *** CD-ROM | disk | FTP | other *** search
-
- #include "Transport.h"
- #include <RJS/Util.h>
- #include <stdio.h>
- #include <osfcn.h>
- #include <libc.h>
- #include <string.h>
-
- extern "C" {
- int dnet_conn(
- const char *node,
- const char *obj,
- int type,
- u_char *opt_out,
- int opt_outl,
- u_char *opt_in,
- int *opt_inl
- );
- struct dn_naddr *dnet_addr(const char *cp);
- struct nodeent *getnodebyname(const char *node);
- int dnet_eof(int s);
- }
-
- int RJS_DECnetSocket::dnet_eof() { return ::dnet_eof(td); }
-
- int RJS_DECnetSocket::passive(const RJS_DECnetAddress &da)
- {
- if (inuse()) close();
- if (!socket()) goto error;
-
- if (!bind(da,da.size())) goto error;
- if (!listen(SOMAXCONN)) goto error;
-
- ss_set(SS_success);
- sex=Passive;
- return 1;
- error:
- if (!return_on_error)
- RJS_Util::crash_and_burn("DECnetSocket","open",ss_message());
- return 0;
- }
-
- int RJS_DECnetSocket::active(const RJS_DECnetAddress &da)
- {
- if (inuse()) close();
- if (!socket()) goto error; // error creating socket
-
- if (!connect(da,da.size())) goto error;
-
- ss_set(SS_success);
- sex=Active;
- return 1;
- error:
- if (!return_on_error)
- RJS_Util::crash_and_burn("RJS_DECnetSocket","open",ss_message());
- return 0;
- }
-
- int RJS_DECnetSocket::dnet_conn(const char *node,const char *obj)
- {
- td = ::dnet_conn(node,obj,type,NULL,NULL,NULL,NULL);
- if (td<0) ss_set(RJS_Status(errno));
- else ss_set(SS_success);
- sex = Active;
- return (ss_ok());
- }
-
- int RJS_DECnetSocket::accept(RJS_DECnetSocket &newsocket)
- {
- if (!ok() || !is_passive()) {
- newsocket.td = -1;
- newsocket.ss_set(SS_error);
- return 0;
- }
-
- if (newsocket.inuse()) newsocket.close();
-
- newsocket = *this;
-
- RJS_DECnetAddress client_addr;
- int clen=client_addr.size();
- newsocket.td = RJS_Socket::accept(client_addr,clen);
- if (newsocket.td < 0 ) {
- newsocket.ss_set(RJS_Status(errno));
- if (return_on_error) return 0;
- RJS_Util::crash_and_burn("RJS_DECnetSocket","accept",ss_message());
- } else {
- newsocket.ss_set(SS_success);
- return 1;
- }
- }
-
-
-